import java.util.TreeMap;





public class PlaceIndexes {

	TreeMap<String, PlaceIndex> indexes;
	
	public PlaceIndexes() {
		indexes = new TreeMap<String, PlaceIndex>();
	}
	
	PlaceIndex attach(CommuteRecord[] records, String key) {
		PlaceIndex index = indexes.get(key);
		if( index == null ) {
			index = new PlaceIndex(key);
			indexes.put(key, index);
		}
		
		index.record(records);
		
		
		return index;
	}
	
	PlaceIndex find(String key) {
		PlaceIndex index = indexes.get(key);
		return index;
	}
	
	PlaceIndex detach(CommuteRecord record, String key) {
		CommuteRecord r = null;
		PlaceIndex index = indexes.get(key);
		if( index != null ) {
			r = index.erase(record);
		}
		
		if( r != null ) {
			index.renewRegionTotal();
		}
		
		return index;
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
